package com.stylefeng.guns.modular.system.warpper;

import java.text.DecimalFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.stylefeng.guns.core.base.warpper.BaseControllerWarpper;
import com.stylefeng.guns.core.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.modular.system.model.Brank;
import com.stylefeng.guns.modular.system.model.Gdhs;
import com.stylefeng.guns.modular.system.model.Gdprice;
import com.stylefeng.guns.modular.system.model.Gpdata;
import com.stylefeng.guns.modular.system.model.HybrankDetail;

public class HyBrankDetailWarpper extends BaseControllerWarpper{
	
	public HyBrankDetailWarpper(List<Map<String, Object>> list) {
        super(list);
    }

    @Override
    public void warpTheMap(Map<String, Object> map) {
    	DecimalFormat df = new DecimalFormat("0.00");
    	
    	Date date = ((Date)map.get("gTdate"));
    	map.put("gTdate", DateUtil.format(date, "yyyy-MM-dd"));
    	String gScode = ((String)map.get("gScode"));
    	String gSname = ((String)map.get("gSname"));
    	
    	Gdhs gdhs =  ConstantFactory.me().getGdhs(gScode);
		Gdprice gdprice =  ConstantFactory.me().getGdprice(gScode);
		Gpdata gpdata = ConstantFactory.me().getGpdata(gScode);
		if(gdhs == null || gdprice == null || gpdata == null) return;
    	
    	String[] gYybCodes = StringUtils.split(((String)map.get("gYybCode")), ",");
    	StringBuffer buffer = new StringBuffer();
    	for(int i = 0; i < gYybCodes.length ; i++){
    		int yybcode = Integer.parseInt(gYybCodes[i]);
    		Brank brank =  ConstantFactory.me().getBrank(yybcode);
    		if(brank == null || brank.getgUpRate1dc() <=0 || brank.getgUpRate2dc() <=0 ){
    			 continue;
    		}
    		HybrankDetail hybrankDetail = new HybrankDetail();
    		hybrankDetail.setgSalesCode(Integer.parseInt(gYybCodes[i]));
    		hybrankDetail.setgTDate(date);
    		hybrankDetail.setgScode(gScode);
    		hybrankDetail = ConstantFactory.me().getHybrankDetail(hybrankDetail);
    		if(hybrankDetail == null){
    			continue;
    		} 
    		buffer.append(hybrankDetail.getgSalesName() + " -- <font color='red'><b> "+hybrankDetail.getgSalesDetail()+" </b></font></br>")
    		.append("上榜一天成功率: <font color='red'><b>" + brank.getgUpRate1dc() + "</b></font>")
    		.append("&nbsp&nbsp|&nbsp&nbsp")
    		.append("上榜两天成功率: <font color='red'><b>" + brank.getgUpRate2dc() + "</b></font>")
    		.append("&nbsp&nbsp|&nbsp&nbsp")
    		.append("上榜三天成功率: <font color='red'><b>" + brank.getgUpRate3dc() + "</b></font>")
    		.append("</br>")
    		.append("净买入(万):" + (hybrankDetail.getgBmoney() > 0 ? "<font color='red'><b>"+df.format(hybrankDetail.getgBmoney()/10000)+"</b></font>" : "<font color='green'><b>"+df.format(hybrankDetail.getgBmoney()/10000)+"</b></font>"))
    		.append("&nbsp&nbsp|&nbsp&nbsp")
    		.append("净卖出(万):" + "<font color='green'><b>"+df.format(hybrankDetail.getgSmoney()/10000)+"</b></font>")
    		.append("&nbsp&nbsp|&nbsp&nbsp")
    		.append("总买卖(万):" + (hybrankDetail.getgPbuy() > 0 ? "<font color='red'><b>"+df.format(hybrankDetail.getgPbuy()/10000)+"</b></font>" : "<font color='green'><b>"+df.format(hybrankDetail.getgPbuy()/10000)+"</b></font>"))
    		.append("</br></br>");
    	}
    	String gSalesDetail = (String)map.get("gSalesDetail");
    	map.put("gSalesDetail", "<font color='red'><b>" + gSalesDetail + "</b></font>");
    	map.put("gYybName", "<font color='Chocolate'><b>" + buffer.toString() + "</b></font>");
    	StringBuffer result = new StringBuffer();
    	result.append("</br>")
		.append("<font color='red'><b>" + gScode + "</b></font>")
		.append("&nbsp&nbsp|&nbsp&nbsp")
		.append("<font color='red'><b>" + gSname + "</b></font>")
		.append("&nbsp&nbsp|&nbsp&nbsp股东增减比例:" + (gdhs.getgZjbl() > 0 ? "<font color='red'><b>"+gdhs.getgZjbl()+"</b></font>" : "<font color='green'><b>"+gdhs.getgZjbl()+"</b></font>"))
		.append("</br>")
		.append("最新价:" + (gdprice.getgPrice() > 0 ? "<font color='red'><b>"+gdprice.getgPrice()+"</b></font>" : "<font color='green'><b>"+gdprice.getgPrice()+"</b></font>"))
		.append("&nbsp&nbsp|&nbsp&nbsp")
		.append("涨跌幅:" + (gdprice.getgZdf() > 0 ? "<font color='red'><b>"+gdprice.getgZdf()+"</b></font>" : "<font color='green'><b>"+gdprice.getgZdf()+"</b></font>"))
		.append("&nbsp&nbsp|&nbsp&nbsp")
		.append("区间涨跌幅:" + (gdprice.getgJqZdf() > 0 ? "<font color='red'><b>"+gdprice.getgJqZdf()+"</b></font>" : "<font color='green'><b>"+gdprice.getgJqZdf()+"</b></font>"))
		.append("</br>")
		.append("私募(阳光):" + (gpdata.getgIsYgsmNum() > 0 ? "<font color='red'><b>"+gpdata.getgIsYgsmNum()+"</b></font>" : "<font color='green'><b>"+gpdata.getgIsYgsmNum()+"</b></font>"))
		.append("&nbsp&nbsp|&nbsp&nbsp")
		.append("私募(个人):" + (gpdata.getgIsGrsmNum() > 0 ? "<font color='red'><b>"+gpdata.getgIsGrsmNum()+"</b></font>" : "<font color='green'><b>"+gpdata.getgIsGrsmNum()+"</b></font>"))
		.append("&nbsp&nbsp|&nbsp&nbsp")
		.append("QFILL:" + (gpdata.getgIsQfillNum() > 0 ? "<font color='red'><b>"+gpdata.getgIsQfillNum()+"</b></font>" : "<font color='green'><b>"+gpdata.getgIsQfillNum()+"</b></font>"))
		.append("</br>")
		.append("基金社保:" + (gpdata.getgIsJjNum() > 0 ? "<font color='red'><b>"+gpdata.getgIsJjNum()+"</b></font>" : "<font color='green'><b>"+gpdata.getgIsJjNum()+"</b></font>"))
		.append("&nbsp&nbsp|&nbsp&nbsp")
		.append("国家队:" + (gpdata.getgIsGjdNum() > 0 ? "<font color='red'><b>"+gpdata.getgIsGjdNum()+"</b></font>" : "<font color='green'><b>"+gpdata.getgIsGjdNum()+"</b></font>"))
		.append("&nbsp&nbsp|&nbsp&nbsp")
		.append("企业年金:" + (gpdata.getgIsQynjNum() > 0 ? "<font color='red'><b>"+gpdata.getgIsQynjNum()+"</b></font>" : "<font color='green'><b>"+gpdata.getgIsQynjNum()+"</b></font>"))
		.append("</br></br>");
    	map.put("gSname", result.toString());
    	double gPbuy = (Double)map.get("gPbuy");
    	map.put("gPbuy", (gPbuy > 0 ? "<font color='red'><b>"+df.format(gPbuy / 10000)+"</b></font>" : "<font color='green'><b>"+df.format(gPbuy / 10000)+"</b></font>"));
    }
    
}
